import { init } from '@rematch/core';
import reduxThunk from 'redux-thunk';
import Immer from '@rematch/immer';
import Loading from '@rematch/loading';
import Select from '@rematch/select';

const context = require.context('../pages', true, /models\.(js|ts)$/);
const models = context
  .keys()
  .map(key => context(key).models)
  .reduce((a, b) => ({...a, [b.name]: b.model}), {});

const store = init({
    models,
    plugins: [Immer, Loading, Select],
    redux: {
        middlewares: [reduxThunk],
        reducers: {}
    }
});

export default store